package com.tjoris.midigateway.ui;

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.UIManager;

public class TestCell
{
	private final JButton fButton;
	private final JSlider fSlider;
	
	public TestCell()
	{
		fButton = new JButton("Test");
		fButton.setOpaque(true);
		
		fSlider = new JSlider(0, 127, 63);
	}
	
	public JButton getButton()
	{
		return fButton;
	}
	
	public JSlider getSlider()
	{
		return fSlider;
	}
	
	public Component getComponent(final MidiEntry entry, final JTable table, final boolean isSelected)
	{
		final Component result;
		if (entry.getAction().isVariable())
		{
			fSlider.setValue(entry.getLastValue());
			result = fSlider;
		}
		else
		{
			result = fButton;
		}
		if (isSelected)
		{
			result.setForeground(table.getSelectionForeground());
			result.setBackground(table.getSelectionBackground());
		}
		else
		{
			result.setForeground(table.getForeground());
			result.setBackground(UIManager.getColor("Button.background"));
		}
		return result;
	}
}
